package com.gy.education.mine;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.gy.education.BaseActivity;
import com.gy.education.R;
import com.gy.education.utils.SelectTimeUtil;
import com.gy.education.utils.SelectTtimeListener;

import java.util.Calendar;

/**
 * 作者：gy on 16/7/14
 * 说明：我的信息
 */
public class MyInfoActivity extends BaseActivity {

    public static int ADD_RESULT = 101;//添加地址
    private ImageView imgScan;
    private TextView tvAddress,tvBirthday,tvFlow,tvHouse,tvSave;
    private RadioGroup rgSex;
    private EditText etQQ,etWX;
    private String strAddress,strBirthday,strFlow,strHouse,strQQ,strWX;
    private String proviceName, cityName, districtName, zipCode;
    private SelectTimeUtil selectTimeUtil;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_my_info);
        setTitleMsg("个人信息");
        imgScan = (ImageView) findViewById(R.id.my_infor_img_scan);
        tvAddress = (TextView) findViewById(R.id.my_infor_tv_addreaa);
        tvBirthday = (TextView) findViewById(R.id.my_infor_tv_birthday);
        tvFlow = (TextView) findViewById(R.id.my_infor_tv_flow);
        tvHouse = (TextView) findViewById(R.id.my_infor_tv_house);
        tvSave = (TextView) findViewById(R.id.my_infor_tv_save);
        rgSex = (RadioGroup) findViewById(R.id.my_infor_rg_sex);
        etQQ = (EditText) findViewById(R.id.my_infor_et_qq);
        etWX = (EditText) findViewById(R.id.my_infor_et_wx);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {
        super.setListener();
        tvAddress.setOnClickListener(this);
        tvBirthday.setOnClickListener(this);
        tvFlow.setOnClickListener(this);
        tvHouse.setOnClickListener(this);
        tvSave.setOnClickListener(this);

        rgSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.my_infor_tv_addreaa://选择地址
                Intent intent = new Intent(this,AddressSelectActivity.class);
                startActivityForResult(intent,ADD_RESULT);
                break;
            case R.id.my_infor_tv_birthday://出生日期
                selectTimeUtil = new SelectTimeUtil(this);
                int year = Calendar.getInstance().get(Calendar.YEAR);
                int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
                int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
                selectTimeUtil.selectYearMonthDay(this.getWindow().getDecorView(), year, month, day, new SelectTtimeListener() {
                    @Override
                    public void setTime(int year, int month, int day, int hour, int minute) {
                        tvBirthday.setText(year+"-"+month+"-"+day);
                    }
                });
                break;
            case R.id.my_infor_tv_flow://宿舍楼

                break;
            case R.id.my_infor_tv_house://选择宿舍

                break;
            case R.id.my_infor_tv_save:
                strAddress = tvAddress.getText().toString();
                strBirthday = tvBirthday.getText().toString();
                strFlow = tvFlow.getText().toString();
                strHouse = tvHouse.getText().toString();
                strQQ = etQQ.getText().toString();
                strWX = etWX.getText().toString();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == ADD_RESULT){
            if (data != null) {
                proviceName = data.getStringExtra("proviceName");
                cityName = data.getStringExtra("cityName");
                districtName = data.getStringExtra("districtName");
                zipCode = data.getStringExtra("zipCode");
                tvAddress.setText(proviceName + cityName + districtName);
            } else {
                tvAddress.setText("");
            }
        }
    }

}
